// pages/mall/mall.js
const app = getApp();
const constant = require('../../constant');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    hotshow: false,
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    hotGoods: [],
    goodsList: []
  },

  getHotGoods: function() {
    let that = this;
    app.get('Goods/getproductlist', {
      type: '5',
      ishot: '1',
      page_no: '1',
      page_count: '3'
    }, function (res) {
      if (res.code == 200 && res.data.data_list.length > 0) {
        let list = res.data.data_list
        for (let i = 0; i < list.length; i++) {
          list[i].goods_img = constant.config.host + list[i].goods_img;
        }
        that.setData({
          hotGoods: list,
          hotshow: true
        })
        if (res.data.data_list.length == 1) {
          that.setData({
            indicatorDots: false,
            autoplay: false
          })
        }
      }
    })
  },
  getGoodsList: function() {
    let that = this;
    app.get('Goods/getproductlist', {
      type: '5',
      ishot: '0',
      page_no: '1',
      page_count: '10'
    }, function (res) {
      if (res.code == 200 && res.data.data_list.length > 0) {
        let list = res.data.data_list
        for (let i = 0; i < list.length; i++) {
          list[i].goods_img = constant.config.host + list[i].goods_img;
        }
        that.setData({
          goodsList: list,
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getHotGoods();
    this.getGoodsList();
  },
  //平台币规则跳转
  toCoinRule: function () {
    wx.navigateTo({
      url: '../coinRule/coinRule'
    })
  },
  //商品跳转
  toProduct: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../mallGoodsDetail/mallGoodsDetail?goods_id=' + id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})